package com.example.app;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager2.widget.ViewPager2;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.app.database.DBMissionData;

public class AddMission extends AppCompatActivity implements View.OnClickListener{

    private TextView title;
    private Button back,complete;
    private CheckBox c1,c2,c3,c4,c5;
    private EditText num,name,place;
    private DBMissionData data;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_mission);

        data=new DBMissionData(this);
        InitView();
    }


    private void changeTab(int position) {

    }

    private void InitView() {
        title=findViewById(R.id.mm_tv);
        title.setText(R.string.add_mission);
        back=findViewById(R.id.mm_back);
        back.setOnClickListener(this);
        complete=findViewById(R.id.am_complete);
        complete.setOnClickListener(this);
        c1=findViewById(R.id.am_sl1);
        c1.setOnClickListener(this);
        c2=findViewById(R.id.am_sl2);
        c2.setOnClickListener(this);
        c3=findViewById(R.id.am_sl3);
        c3.setOnClickListener(this);
        c4=findViewById(R.id.am_sl4);
        c4.setOnClickListener(this);
        c5=findViewById(R.id.am_sl5);
        c5.setOnClickListener(this);
        num=findViewById(R.id.am_num);
        name=findViewById(R.id.am_name);
        place=findViewById(R.id.am_place);
    }

    @Override
    public void onClick(View view) {
        switch(view.getId())
        {
            case R.id.mm_back:
                startActivity(new Intent(this,MyMission.class));
                finish();
                break;
            case R.id.am_complete:
                String t=num.getText().toString().trim();
                int missionNum=Integer.parseInt(t);
                String missionName=name.getText().toString().trim();
                String missionPlace=place.getText().toString().trim();
                String missionLevel="未定级";
                if(c1.isChecked()) missionLevel="一级";
                if(c2.isChecked()) missionLevel="二级";
                if(c3.isChecked()) missionLevel="三级";
                if(c4.isChecked()) missionLevel="四级";
                if(c5.isChecked()) missionLevel="五级";

                if(!TextUtils.isEmpty(t)&& !TextUtils.isEmpty(missionName)&& !TextUtils.isEmpty(missionPlace))
                {
                    data.add(missionNum,missionName,missionPlace,missionLevel,null,0);
                    Toast.makeText(this,"成功添加任务",Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(this,MyMission.class));
                    finish();
                }
                else
                {
                    Toast.makeText(this,"请将信息填写完整",Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.am_sl1:
                    c1.setChecked(true);
                    c2.setChecked(false);
                    c3.setChecked(false);
                    c4.setChecked(false);
                    c5.setChecked(false);
                break;
            case R.id.am_sl2:
                    c1.setChecked(false);
                    c2.setChecked(true);
                    c3.setChecked(false);
                    c4.setChecked(false);
                    c5.setChecked(false);
                break;
            case R.id.am_sl3:
                    c1.setChecked(false);
                    c2.setChecked(false);
                    c3.setChecked(true);
                    c4.setChecked(false);
                    c5.setChecked(false);
                break;
            case R.id.am_sl4:
                    c1.setChecked(false);
                    c2.setChecked(false);
                    c3.setChecked(false);
                    c4.setChecked(true);
                    c5.setChecked(false);
                break;
            case R.id.am_sl5:
                    c1.setChecked(false);
                    c2.setChecked(false);
                    c3.setChecked(false);
                    c4.setChecked(false);
                    c5.setChecked(true);
                break;
        }
    }
}